import gugga.collections.HashTable;
import test_framework.test.unit.info.AssertEqualsInfo;
import test_framework.test.unit.TestCase;
/**
 * @author stefan
 */
class guggaLibTests.HashTableTest 
		extends TestCase
{
	function HashTableTest(Void) 
	{
		super();
	}
	
	function testIterationWithForIn ()
	{
		var table : HashTable = new HashTable();
		
		table.add("key1", { name: "object1" } );
		table.add("key2", { name: "object2" } );
		table.add("key3", { name: "object3" } );
		
		assertEquals(
			"",
			3,
			table.count
		);
	}
	
	function testComplex ()
	{
		var table : HashTable = new HashTable();
		
		var objA : Object = new Object ();
		var objB : Object = new Object ();
		var objC : Object = new Object ();
		
		var key1 : String = "key1";
		var key2 : String = "key2";
		var key3 : String = "key3";
		
		var obj0 : Object = new Object ();
		var objZ : Object = new Object ();
		
		table.add(key1, objA);
		table.add(key2, objB);
		table.add(key3, objC);
		
		assertTrue(
			"table should contains key obj1",
			table.containsKey(key1)
		);
		
		assertFalse(
			"table should not contains key obj0",
			table.containsKey(obj0)
		);
		
		assertEquals(
			"table.count returns unexpected result: " + table.count + ", should be 3",
			3,
			table.count
		);
		
		assertTrue(
			"table should contains objA",
			table.containsValue(objA)
		);
		
		assertFalse(
			"table should not contains objZ",
			table.containsValue(objZ)
		);
		
		table.remove(key2);
		
		assertFalse(
			"table should not contains objB after remove",
			table.containsValue(objB)
		);
		
		assertEquals(
			"getKeyByValue returns unexpected results",
			key3,
			table.getKeyByValue(objC)
		);
		
		var table2 :  HashTable = HashTable(table.clone());
		
		assertEquals(
			"table.count returns unexpected result: " + table.count + ", should be 3",
			2,
			table2.count
		);
		
		assertEquals(
			"getValue unexpected result",
			objC,
			table2.getValue(key3)
		);
		
	}
}